<template>
  <div>
    <!-- 历史记录 -->
    <div class="his-hot" v-show="isShowHistory">
      <div class="hd">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="clearClick"/>
      </div>
      <div class="bd">
        <van-tag
          plain
          type="default"
          v-for="(item, index) in historyListData"
          :key="index"
          @click="tagClick(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>
    <!-- 热门搜索 -->
    <div class="his-hot">
      <div class="hd">
        <h4>热门搜索</h4>
      </div>
      <div class="bd">
        <van-tag
          plain
          type="default"
          :class="item.is_hot == 1 ? 'red' : ''"
          v-for="(item, index) in hotKeywordListData"
          :key="index"
          @click="tagClick(item.keyword)"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import {ClearSearchHistory} from "@/request/api.js"
export default {
  props: ["historyListData", "hotKeywordListData"],
  data() {
    return {
      isShowHistory:true,
    };
  },
  created() {},
  mounted() {},
  methods: {
    tagClick(val){
      this.$emit('onSearch',val);
    },
    clearClick(){
      ClearSearchHistory().then(res=>{
        console.log(res);
        this.isShowHistory = false;
        // 在html可以使用Toast，在js中需要写成this.$toast全局变量
        this.$toast.success('成功文案');
      })
    }
  },
};
</script>

<style scoped lang="less">
.his-hot {
  background-color: #ffffff;
  padding: 0.05rem 0.1rem;
  margin-bottom: 0.15rem;
  .hd {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.05rem;
    font-size: 0.2rem;
    margin-bottom: 0.1rem;
  }
  .van-tag {
    padding: 0.02rem 0.05rem;
    margin-right: 0.05rem;
    margin-bottom: 0.1rem;
  }
  .red {
    color: red;
  }
}
</style>
